import React, { Component } from 'react';
 import {user_regsiter} from "../uilt/api"
class App extends Component {
  constructor(props){
    super(props);
    this.state={
      phone:"",
      pass:"",
      password:""
    }
  }
  register(){
    if(this.state.phone&&this.state.pass&&this.state.password){
      if(this.state.pass===this.state.password){
        var {password,...params}=this.state
        user_regsiter(params).then((res)=>{
         console.log(res);
     
         })
      }
    }
    // 把state对象里面的数据除了password,其他都解构到params里面
   
  }
  hanlechang(e){
  this.setState({
    // 动态把input里面value赋给state里面
    [e.currentTarget.name]:e.currentTarget.value
  },()=>{
    // 想要打印最新数据在state回调里面打印
    console.log(this.state.phone);
  })
  }
  render() {
    return (
      <div className='login'>
 <div className="title">
   注册页面
 </div>
 <div className="input">
   <input type="text" name="phone" id="" defaultValue={this.state.phone} onChange={(e)=>{this.hanlechang(e)}}/>
 </div>
 <div className="input">
   <input type="password" name="pass" id="" defaultValue={this.state.pass} onChange={(e)=>{
    this.hanlechang(e)
   }}/>
    <div className="input">
   <input type="password" name="password" id="" defaultValue={this.state.password} onChange={(e)=>{
    this.hanlechang(e)
   }}/>
 </div>
 <div className="input">
   <input type="button" onClick={()=>{this.register()}} value="注册" />
 </div>
   </div>
     </div>
    );
  }
}

export default App;